package test;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import dsa.LinkedList;

public class CaseyCapriceTest
{

	LinkedList bobsFriends;	
	
	@Before
	public void setUp() throws Exception
	{
		bobsFriends = new LinkedList();
		
		for( int i = 0; i < 25; i++ )
		{
			bobsFriends.addLast(i);
		}	
	}

	@After
	public void tearDown() throws Exception 
	{		
	}

	@Test	
	public void getTest()
	{
		for( int i = 0; i < 25; i++ )
		{
			assertTrue(bobsFriends.get(i).equals(i));
		}
	}
	
	@Test
	public void addLastgetLastTest()
	{
		bobsFriends.addLast(25);
		assertTrue(bobsFriends.getLast().equals(25));
	}
	
	@Test
	public void addFirstgetFirstTest()
	{
		bobsFriends.addFirst(100);
		assertTrue(bobsFriends.getFirst().equals(100));
	}
	
	@Test
	public void removeTest()
	{
		for ( int i = bobsFriends.size() - 1; i >= 0; i-- )
		{
			bobsFriends.remove(i);
		}
		assertTrue( bobsFriends.size() == 0 );
	}
	
	@Test
	public void removeFirstTest()
	{
		assertTrue(bobsFriends.getFirst().equals(0));
		bobsFriends.removeFirst();
		assertFalse(bobsFriends.getFirst().equals(0));
	}
	
	@Test
	public void removeLastTest()
	{
		assertTrue(bobsFriends.getLast().equals(24));
		bobsFriends.removeLast();
		assertFalse(bobsFriends.getLast().equals(24));
	}
	
	@Test
	public void setTest()
	{
		bobsFriends.set(7, 70);
		
		assertTrue(bobsFriends.get(7).equals(70));
	}
	
	@Test
	public void containsTest()
	{
		for( int i = 0; i < bobsFriends.size(); i++ )
		{
			assertTrue(bobsFriends.contains(i));
		}		
	}
	
	@Test
	public void cloneTest()
	{
		LinkedList clone = (LinkedList) bobsFriends.clone();
		
		for ( int i = 1; i < bobsFriends.size(); i++ )
		{
			assertTrue(bobsFriends.get(i).equals(clone.get(i)));	
		}
	}
	
	@Test
	public void toArrayTest()
	{
		Object [] array;
		
		array = bobsFriends.toArray();
		
		for ( int i = 0; i < bobsFriends.size() - 1; i++ )
		{
			assertTrue(array[i].equals(bobsFriends.get(i)));
		}				
	}
	
	
	public void firstIndexOfTest()
	{
		for ( int i = 0; i < bobsFriends.size() - 1; i++)
		{
			assertTrue(bobsFriends.indexOf(i) == i);
		}
		assertTrue(bobsFriends.indexOf(100) == -1);
	}
	
	public void test() 
	{
		
	}
	
	@Test
	public  void hasNextTest()
	{		
		assertTrue(bobsFriends.listIterator(0).hasNext());
		assertFalse(bobsFriends.listIterator(bobsFriends.size()).hasNext());
	}
	
	@Test
	public void hasPreviousTest()
	{
		assertTrue(bobsFriends.listIterator(1).hasPrevious());
		assertFalse(bobsFriends.listIterator(0).hasPrevious());
	}
	
	@Test
	public void iteratorAddTest()
	{
		bobsFriends.listIterator(5).add(1);
		assertTrue(bobsFriends.get(5).equals(1));
	}
	
	@Test
	public void iteratorSetTest()
	{
		bobsFriends.listIterator(5).set(100);
		assertTrue(bobsFriends.get(5).equals(100));
	}
	
	@Test
	public void iteratorRemoveTest()
	{
		bobsFriends.listIterator(0).remove();
		assertFalse(bobsFriends.get(0).equals(0));
	}
	
	@Test
	public void nextIndexTest()
	{
		assertTrue(bobsFriends.listIterator(5).nextIndex() == 6);		
	}
	
	@Test
	public void previousIndexTest()
	{
		assertTrue(bobsFriends.listIterator(3).previousIndex() == 2);
	}
	
	@Test
	public void nextTest()
	{
		assertTrue(bobsFriends.listIterator(3).next().equals(bobsFriends.listIterator(4) ) );
	}
	
	@Test
	public void previousTest()
	{
		assertTrue(bobsFriends.listIterator(4).previous().equals(bobsFriends.listIterator(3) ) );
	}
	
	
	
	

}
